import  {parse} from 'qs'
export default {
    namespace:'formOne',
    state:{
        tableList:[],
        title:'继承的老标题',
    },
    //同步方法，存值
    reducers:{
        changeTitle(state,action){
			const{tableList} = state 
            return({
                title:action.payload.title,
                tableList,

                 
            })
        },
        changeTable(state,{tableList}){//第二参数是action
			const{title} = state
            return({
                title,
				tableList,//tableList:tableList
            })
        }
    },
    //异步方法
    effects:{
        *init({tableList},{call,put,select}){//第一参数是action
            yield put({//action对象
                type:'changeTable',
                tableList//tableList:tableList
            })
        },
        *dchangetitle({totalTitle},{call,put,select}){//action对象
			/*   const{testMessage} = yield select(state=>state.test) */
			  yield put({
				  type:'changeTitle',
				  payload:{
					  title:totalTitle
				  }
			  })
		  },
        *jump({currentPageNum},{call,put,select}){//第一参数是action
            let a,data=[]
            console.log('44444'+currentPageNum)
            switch(currentPageNum){
                case 1:a=0;break;
                case 2:a=5;break;
                case 3:a=10;break;
            }
            for ( let i = a; i <a+5; i++) {
                data.push({
                  key: i,
                  name: `梁美容${i}`,
                  age: 97,
                  address: `广东. ${i}`,
                });
              }  
            yield put({//action对象
                type:'changeTable',
                tableList:data//tableList:tableList
            })
		},
    },
    subscriptions:{
        setup({dispatch,history}){
            return history.listen(({pathname,search})=>{
                const query = parse(search.split('?')[1]);
                const data = [];
                for (let i = 0; i <5; i++) {
                  data.push({
                    key: i,
                    name: `梁美容${i}`,
                    age: 97,
                    address: `广东. ${i}`,
                  });
                } 
                if(pathname === '/formOne'){dispatch({type:'init',tableList:data})}
            })
        }
    },
}